import axiosRequest from "@/api/axiosRequest.ts";

const BaseUrl = '/admin/article'

const getArticlePage = (article:Partial<ArticleSearch>) => axiosRequest({
    url: BaseUrl + '/page',
    method: 'GET',
    params: article
})

const addArticle = (article:Article) => axiosRequest({
    url: BaseUrl + '/add',
    method: 'POST',
    data: article
})

const updateArticle = (article:Article) => axiosRequest({
    url: BaseUrl + '/update',
    method: 'PUT',
    data: article
})

const getArticleDetail = (id:number) => axiosRequest({
    url: BaseUrl + '/detail' ,
    method: "GET",
    params: {
        id: id
    }
})

const deleteArticle = (id:number) => axiosRequest({
    url: BaseUrl + '/delete',
    method: 'DELETE',
    params: {
        id: id
    }
})

const setTopArticle = (id:number) => axiosRequest({
    url: BaseUrl + '/setTopArticle' ,
    method: "GET",
    params: {
        articleId: id
    }
})

export const articleApi = {
    getTopArticle : () => axiosRequest.get(BaseUrl + '/getTopArticle'),
    setTopArticle,
    getArticlePage,
    addArticle,
    updateArticle,
    getArticleDetail,
    deleteArticle
}
